package com.doit.day02

import scala.beans.BeanProperty

object _03_面向对象 {
  def main(args: Array[String]): Unit = {
//    val pig: Pig = new Pig()
    //只有带参构造，没有空参构造了
   val p1 = new Pig1()
   val p2 = new Pig1(100.233,"hehe")
   val p3 = new Pig1(100.233,"hehe",18)
   val p4 = new Pig1(100.233,"hehe",18,"male")

    p1.eat()
  }
}

//创建一个类
class Pig{
  @BeanProperty
  val name:String = "佩奇"
  @BeanProperty
  val age:Int = 2
  @BeanProperty
  var gender :String = "male"

  def eat()={
    println("我贼能吃！！")
  }
  val sleep = ()=>{println("我也贼能睡！不要吃我")}
}

//辅助构造器
//类和构造方法交织在一起
class Pig1(){
  var weight:Double = 100.22
  var name:String = "佩奇"
  var age:Int = 2
  var gender :String = "male"

  //辅助构造器第一行必须得调用主构造器或者其他的辅助构造器
  def this(weight:Double, name:String)={
    this()
    this.weight = weight
    this.name = name
  }

  def this(weight:Double, name:String,age:Int)={
    this(weight,name)
    this.age = age
  }

  def this(weight:Double, name:String,age:Int,gender :String)={
    this()
    this.weight = weight
    this.name = name
    this.age = age
    this.gender = gender
  }




  def eat()={
    println("我贼能吃！！")
  }
  val sleep = ()=>{println("我也贼能睡！不要吃我")}
}
